package com.poolsoft.kasa;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class KisiVeritabani extends SQLiteOpenHelper {
	// Database, tablo ve tabodaki column adlari
	public static final String DATABASE_NAME = "poolsoft";
	public static final String TABLE_NAME = "kisi";
	public static final String KISI_ADI = "AD";
	public static final String KISI_SOYAD = "SOYAD";
	public static final String KISI_YAS = "DTARIHI";
	public static final String KISI_DTARIHI = "DTARIHI";
	public static final String F_TEL1 = "TEL1";
	public static final String F_TEL2 = "TEL2";
	public static final String F_TEL3 = "TEL3";
	public static final String F_TEL4 = "TEL4";
	public static final String F_TEL5 = "TEL5";
	
	public static final int DATABASE_VERSION = 1;

	public KisiVeritabani(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);

	}

	// table ve alanlarini olsuturuyor.Dikkat + ile string eklediginizde
	// oncekinden ayirmak
	// icin bosluk birazkin. Mesela sql="CREATE TABLE bosluk"+TABLE_NAME gibi
	@Override
	public void onCreate(SQLiteDatabase dbObject) {
		String tablo1 = "CREATE TABLE hareketler (hareket_id INTEGER PRIMARY KEY AUTOINCREMENT, kasa_id INTEGER not null, hesap_id INTEGER not null, hareket_turu TEXT not null, tutar REAL not null, tarih DATE not null, bakiye REAL, aciklama TEXT);";
		String tablo2 = "CREATE TABLE hesaplar (hesap_id INTEGER PRIMARY KEY AUTOINCREMENT, adi TEXT  not null, soyadi TEXT not null, tel TEXT, mail TEXT, aciklama TEXT);";
		String tablo3 = "CREATE TABLE kasa (kasa_id INTEGER PRIMARY KEY AUTOINCREMENT, hesap_id INTEGER not null, kasa TEXT, gelir REAL, gider REAL, bakiye REAL);";		
		String tablo4 = "CREATE TABLE kullanici (kullanici_id INTEGER PRIMARY KEY AUTOINCREMENT, hesap_id INTEGER not null, kul_adi TEXT not null, kul_sifre TEXT not null);";
				
		dbObject.execSQL(tablo1+" \n"+tablo2+" \n"+tablo3+" \n"+tablo4+"");

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (oldVersion >= newVersion)
			return;

		String sql = null;
		if (oldVersion == 1)
			sql = "alter table " + TABLE_NAME + " add note text;";
		if (oldVersion == 2)
			sql = "";

		Log.d("EventsData", "onUpgrade	: " + sql);
		if (sql != null)
			db.execSQL(sql);

	}

}
